Merge remote-tracking branch 'cmr/master'
authorAlex Crichton <alex@alexcrichton.com>
Wed, 27 Aug 2014 15:04:38 +0000 (08:04 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 27 Aug 2014 15:04:38 +0000 (08:04 -0700)
Conflicts:
src/cargo/ops/cargo_run.rs
tests/test_cargo_run.rs

1  2 
src/bin/run.rs
src/cargo/ops/cargo_run.rs
tests/support/mod.rs
tests/test_cargo_cross_compile.rs
tests/test_cargo_run.rs

diff --cc src/bin/run.rs
index 7d973cb3f8d4e067344f145e7626bbebc2b4596b,0000000000000000000000000000000000000000..4e0ed4d83dde4f56d21192f64c3aa50f86788abf
mode 100644,000000..100644
--- /dev/null
@@@ -1,53 -1,0 +1,55 @@@
-         env: "compile",
 +use std::io::process::ExitStatus;
 +use docopt;
 +
 +use cargo::ops;
 +use cargo::core::{MultiShell};
 +use cargo::util::{CliResult, CliError};
 +use cargo::util::important_paths::{find_root_manifest_for_cwd};
 +
 +docopt!(Options, "
 +Run the main binary of the local package (src/main.rs)
 +
 +Usage:
 +    cargo run [options] [--] [<args>...]
 +
 +Options:
 +    -h, --help              Print this message
 +    -j N, --jobs N          The number of jobs to run in parallel
++    --release               Build artifacts in release mode, with optimizations
++    --target TRIPLE         Build for the target triple
 +    -u, --update-remotes    Deprecated option, use `cargo update` instead
 +    --manifest-path PATH    Path to the manifest to execute
 +    -v, --verbose           Use verbose output
 +
 +All of the trailing arguments are passed as to the binary to run.
 +",  flag_jobs: Option<uint>, flag_target: Option<String>,
 +    flag_manifest_path: Option<String>)
 +
 +pub fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
 +    shell.set_verbose(options.flag_verbose);
 +    let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
 +
 +    let mut compile_opts = ops::CompileOptions {
 +        update: options.flag_update_remotes,
-         target: None,
++        env: if options.flag_release { "release" } else { "compile" },
 +        shell: shell,
 +        jobs: options.flag_jobs,
++        target: options.flag_target.as_ref().map(|t| t.as_slice()),
 +        dev_deps: true,
 +    };
 +
 +    let err = try!(ops::run(&root, &mut compile_opts,
 +                            options.arg_args.as_slice()).map_err(|err| {
 +        CliError::from_boxed(err, 101)
 +    }));
 +    match err {
 +        None => Ok(None),
 +        Some(err) => {
 +            Err(match err.exit {
 +                Some(ExitStatus(i)) => CliError::from_boxed(box err, i as uint),
 +                _ => CliError::from_boxed(box err, 101),
 +            })
 +        }
 +    }
 +}
 +
index eebdc5d3c11fd4e79080eb59a5e36a214422d385,ae5e83ce3cfc1000617ff15207af4a1750e44050..100918658ca21be9ee15401b3b5b7aeaaeec32af
@@@ -11,20 -11,17 +11,24 @@@ pub fn run(manifest_path: &Path
      let mut src = try!(PathSource::for_path(&manifest_path.dir_path()));
      try!(src.update());
      let root = try!(src.get_root_package());
 +    let mut bins = root.get_manifest().get_targets().iter().filter(|a| {
 +        a.is_bin() && a.get_profile().is_compile()
 +    });
 +    let bin = try!(bins.next().require(|| {
 +        human("a bin target must be available for `cargo run`")
 +    }));
 +    match bins.next() {
 +        Some(..) => return Err(human("`cargo run` requires that a project only \
 +                                      have one executable")),
 +        None => {}
 +    }
  
      let compile = try!(ops::compile(manifest_path, options));
-     let exe = manifest_path.dir_path().join("target").join(bin.get_name());
+     let mut exe = manifest_path.dir_path().join("target");
+     if options.env == "release" {
+         exe = exe.join("release");
+     }
 -    let exe = exe.join(root.get_name());
++    let exe = exe.join(bin.get_name());
      let exe = match exe.path_relative_from(&os::getcwd()) {
          Some(path) => path,
          None => exe,
Simple merge
Simple merge
index 7ecb48a76ecaecff32f39d27c760a321df390663,860a62e51f5948b69a87c37376a98a541a196398..9b967432ae95f4c1a3c1bdbaab06b943e1577618
@@@ -132,20 -114,26 +132,44 @@@ test!(run_dylib_dep 
                  execs().with_status(0));
  })
  
+ test!(release_works {
+     let p = project("foo")
+         .file("Cargo.toml", r#"
+             [project]
+             name = "foo"
+             version = "0.0.1"
+             authors = []
+         "#)
+         .file("src/main.rs", r#"
+             fn main() { if !cfg!(ndebug) { fail!() } }
+         "#);
+     assert_that(p.cargo_process("cargo-run").arg("--release"),
+                 execs().with_status(0).with_stdout(format!("\
+ {compiling} foo v0.0.1 ({dir})
+ {running} `target{sep}release{sep}foo`
+ ",
+         compiling = COMPILING,
+         running = RUNNING,
+         dir = path2url(p.root()),
+         sep = path::SEP).as_slice()));
+     assert_that(&p.release_bin("foo"), existing_file());
+ })
++
 +test!(run_bin_different_name {
 +    let p = project("foo")
 +        .file("Cargo.toml", r#"
 +            [project]
 +            name = "foo"
 +            version = "0.0.1"
 +            authors = []
 +
 +            [[bin]]
 +            name = "bar"
 +        "#)
 +        .file("src/bar.rs", r#"
 +            fn main() { }
 +        "#);
 +
 +    assert_that(p.cargo_process("run"), execs().with_status(0));
 +})